/**
 *
 * Copyright (c) 2011, Anusorn B. All rights reserved.
 *
 * This is proprietary source code of Anusorn B.
 *
 */

/**
 * 
 */
package com.nk.system.dao;

/**
 * @author Anusorn
 *
 */

import java.io.Serializable;
import java.util.List;

import com.nk.system.common.search.ExampleOptions;
import com.nk.system.common.search.Filter;
import com.nk.system.common.search.ISearch;
import com.nk.system.common.search.SearchResult;

public interface GenericDAO<T, ID extends Serializable> {

	T findById(ID id, boolean lock);

	List<T> findAll();

	// List<T> findByCriteria(DetachedCriteria dc, int pageNumber, int pageSize);
	List<T> findByExample(T exampleInstance);

	List<T> findByExample(T exampleInstance, int pageNumber, int pageSize);

	List<T> findByExample(T exampleInstance, String[] excludeProperty);

	List<T> findByExample(T exampleInstance, String[] excludeProperty, int pageNumber, int pageSize);

	T saveOrUpdate(T entity);

	T update(T entity);

	T save(T entity);

	void delete(T entity);

	// int countByCriteria(DetachedCriteria dc);

	T[] find(ID... ids);

	T getReference(ID id);

	T[] getReferences(ID... ids);

	void persist(T... entities);

	T merge(T entity);

	T[] merge(T... entities);

	T[] save(T... entities);

	boolean deleteById(ID id);

	void deleteByIds(ID... ids);

	/**
	 * Search for entities given the search parameters in the specified <code>ISearch</code> object.
	 * 
	 * @param RT
	 *        The result type is automatically determined by the context in which the method is called.
	 */
	<RT> List<RT> search(ISearch search);

	/**
	 * Search for a single entity using the given parameters.
	 * 
	 * @param RT
	 *        The result type is automatically determined by the context in which the method is called.
	 */
	<RT> RT searchUnique(ISearch search);

	/**
	 * Returns the total number of results that would be returned using the given <code>ISearch</code> if there were no
	 * paging or maxResults limits.
	 */
	int count(ISearch search);

	/**
	 * Returns a <code>SearchResult</code> object that includes both the list of results like <code>search()</code> and
	 * the total length like <code>count()</code>.
	 * 
	 * @param RT
	 *        The result type is automatically determined by the context in which the method is called.
	 */
	<RT> SearchResult<RT> searchAndCount(ISearch search);

	/**
	 * Returns <code>true</code> if the object is connected to the current Hibernate session.
	 */
	boolean isAttached(T entity);

	/**
	 * Refresh the content of the given entity from the current datastore state.
	 */
	void refresh(T... entities);

	/**
	 * Generates a search filter from the given example using default options.
	 */
	Filter getFilterFromExample(T example);

	/**
	 * Generates a search filter from the given example using the specified options.
	 */
	Filter getFilterFromExample(T example, ExampleOptions options);

}